package controller.api;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;

import common.inter.ServicerStationInter;
import common.inter.StaffStationInter;
import enums.RepaireType;
import model.Repaire;
import service.RepaireService;

public class ApiRepaireController extends BaseApiController {
	@Inject RepaireService repaireService ;

	@Before(ServicerStationInter.class)
	public void list() {
	    Kv kv = getParamKv() ;
	    kv.set("tr.stationId", getStation().getId());
	    Integer pageNumber = getParaToInt("pageNumber", 1);
	    Integer pageSize = getParaToInt("pageSize", 10);
	    set("page", repaireService.getApiPage( kv , pageNumber, pageSize));
	    renderJson();
	}

	public void typeList() {
		renderJson("list" , RepaireType.toList() );
	}

	@Before(StaffStationInter.class)
	public void save() {
		Repaire repaire = getModel(Repaire.class , "x");
        Ret ret = repaireService.save(repaire , getStaff() , getStation());
        renderJson(ret);
	}
}
